import { ref, reactive } from 'vue'

export interface CollapseStates {
  basicInfo: boolean
  diagnosisInfo: boolean
  medicalInstitution: boolean
  specialistAssessment: boolean
  presentIllness: boolean
  pastHistory: boolean
  personalHistory: boolean
  familyHistory: boolean
  surgeryHistory: boolean
  allergyHistory: boolean
  vaccinationScreening: boolean
  periodicHealthCheck: boolean
  lifestyleImprovement: boolean
  allergyPrevention: boolean
  treatmentPlan: boolean
  chiefComplaint: boolean
  healthAssessment: boolean
  healthDemandAttributeOptimization: boolean
  admission: boolean
  measures: boolean
  evaluation: boolean
  feedback: boolean
}

export function useCollapseState() {
  const collapseStates = ref<CollapseStates>({
    basicInfo: false,
    diagnosisInfo: false,
    medicalInstitution: false,
    specialistAssessment: false,
    presentIllness: false,
    pastHistory: false,
    personalHistory: false,
    familyHistory: false,
    surgeryHistory: false,
    allergyHistory: false,
    vaccinationScreening: false,
    periodicHealthCheck: false,
    lifestyleImprovement: false,
    allergyPrevention: false,
    treatmentPlan: false,
    chiefComplaint: false,
    healthAssessment: false,
    healthDemandAttributeOptimization: false,
    admission: false,
    measures: false,
    evaluation: false,
    feedback: false,
  })

  const toggleCollapse = (section: keyof CollapseStates) => {
    collapseStates.value[section] = !collapseStates.value[section]
  }

  const expandAll = () => {
    Object.keys(collapseStates.value).forEach(key => {
      collapseStates.value[key as keyof CollapseStates] = true
    })
  }

  const collapseAll = () => {
    Object.keys(collapseStates.value).forEach(key => {
      collapseStates.value[key as keyof CollapseStates] = false
    })
  }

  return {
    collapseStates,
    toggleCollapse,
    expandAll,
    collapseAll
  }
}
